<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>添加菜单</title>
    <link rel="stylesheet" type="text/css" href="/static/h+/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="/static/h+/css/font-awesome.min93e3.css?v=4.4.0">
    <!-- Data Tables -->
    <link rel="stylesheet" type="text/css" href="/static/h+/css/plugins/iCheck/custom.css">
    <link rel="stylesheet" type="text/css" href="/static/h+/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="/static/h+/css/style.min.css?v=4.1.0">
    <link rel="stylesheet" type="text/css" href="/static/layer/skin/layer.css">
    <style type="text/css">
        .form-control{width: 200px;}
    </style>
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
  <div class="row">
    <div class="col-sm-12">
      <div class="ibox float-e-margins">
        <div class="ibox-title">
          <h5>添加菜单</h5>
        </div>
        <div class="ibox-content">
          <form class="form-horizontal" onsubmit="return false">
            <div class="form-group">
              <label class="col-sm-2 control-label">所属模块</label>
                <div class="col-sm-10">
                  <select class="form-control" id="modular">
                    <option value="0">…所属模块…</option>
                    {foreach $mods as $item}
                    <option value="{$item.id}">{$item.title}</option>
                    {/foreach}
                  </select>
                </div>
              </div>
              <div class="hr-line-dashed"></div>
              <div class="form-group">
                <label class="col-sm-2 control-label">父菜单</label>
                <div class="col-sm-10">
                  <select class="form-control" id="pid">
                    <option value="0">…父级菜单…</option>
                  </select>
                </div>
              </div>
              <div class="hr-line-dashed"></div>
              <div class="form-group">
                <label class="col-sm-2 control-label">标识</label>
                <div class="col-sm-10">
                  <input type="text" class="form-control" id="identity">
                </div>
              </div>
              <div class="hr-line-dashed"></div>
              <div class="form-group">
                <label class="col-sm-2 control-label">名称</label>
                <div class="col-sm-10">
                  <input type="text" class="form-control" id="title">
                </div>
              </div>
              <div class="hr-line-dashed"></div>
              <div class="form-group">
                <label class="col-sm-2 control-label">链接</label>
                <div class="col-sm-10">
                  <input type="text" class="form-control" id="url">
                </div>
              </div>
              <div class="hr-line-dashed"></div>
              <div class="form-group">
                <label class="col-sm-2 control-label">排序</label>
                <div class="col-sm-10">
                  <input type="text" class="form-control" id="sort" value="99">
                </div>
              </div>
              <div class="hr-line-dashed"></div>
              <div class="form-group">
                <label class="col-sm-2 control-label">是否显示</label>
                <div class="col-sm-10">
                  <div class="radio i-checks">
                    <label class><div class="iradio_square-green"><input type="radio" value="0" name="is_hide" style="position: absolute; opacity: 0;"><ins class="iCheck-helper"></ins></div>显示</label>
                    <label class><div class="iradio_square-green"><input type="radio" value="1" name="is_hide" style="position: absolute; opacity: 0;"><ins class="iCheck-helper"></ins></div>隐藏</label>
                  </div>
                </div>
              </div>
              <div class="hr-line-dashed"></div>
              <div class="form-group">
                <div class="col-sm-4 col-sm-offset-2">
                  <input class="btn btn-primary" type="button" id="save" value="保存内容">
                  <input class="btn btn-white" type="button" id="cancel" value="取消">
                </div>
              </div>
          </form>
        </div>
      </div>
    </div>
  </div>
</div>
</body>
<script type="text/javascript" src="/static/h+/js/jquery.min.js"></script>
<script type="text/javascript" src="/static/h+/js/plugins/iCheck/icheck.min.js"></script>
<script type="text/javascript" src="/static/layer/layer.js"></script>
<script type="text/javascript">
    $(function(){
        $(".i-checks").iCheck({checkboxClass: "icheckbox_square-green", radioClass: "iradio_square-green",});
        $('#modular').change(function(){
            $('#pid').html('<option value="0">…父级菜单…</option>')
            $mid = $(this).val()
            $.ajax({
                type: 'post', dataType: 'json', cache: false,
                url: '{:url("get_menu")}',
                data: {'mid': $mid},
                success: function($data){
                    if ($data.status == 0 && $data.menu != null) {
                        $str = '';
                        $($data.menu).each(function(i, v){
                            $str += '<option value="' + v.id + '">' + v.title + '</option>'
                        });
                        $('#pid').append($str);
                    }
                }
            })
        })
        $('#cancel').click(function(){
            location.href = '{:url("lists")}';
        });
        $('#save').click(function(){
            var mid=$('#modular').val(), pid = $('#pid'), identity = $('#identity'), title = $('#title'), url = $('#url'), sort = $('#sort').val(), is_hide = $('input[name="is_hide"]:checked').val();
            if (identity.val() == '') {
                layer.msg('标识不能为空', {icon: 5, time: 1000}, function(){
                    identity.focus();
                });
                return false;
            }
            if (title.val() == '') {
                layer.msg('菜单名称不能为空', {icon: 5, time: 1000}, function(){
                    title.focus();
                });
                return false;
            }
            if (!is_hide) {
                layer.msg('请选择是否在左则显示');
                return false;
            }
            $.ajax({
                type: 'post', cache: false, dataType: 'json',
                url: '{:url("add")}',
                data: {'modular': mid, 'pid': pid.val(), 'identity': identity.val(), 'title': title.val(), 'url': url.val(), 'sort': sort, 'is_hide': is_hide},
                success: function(data){
                    if (data.status == 0) {
                        layer.confirm(data.info + '<br />是否继续添加？', {
                            btn: ['是', '否'],
                            shade: false,
                            closeBtn: 0
                        }, function(){
                            location.reload();
                        }, function(){
                            location.href = '{:url("lists")}'
                        });
                    }else{
                        layer.msg(data.info, {icon: 5, time: 1000});
                    }
                }
            });
        });
    });
</script>
</html>